<?php

namespace plugin\admin\app\controller\novel;

use plugin\admin\app\logic\banner\BannerLogic;
use plugin\admin\app\logic\novel\ChapterLogic;
use plugin\admin\app\logic\novel\NovelLogic;
use support\Request;
use support\Response;
use plugin\admin\app\controller\AuthController;
use support\exception\BusinessException;

/**
 * Banner管理 
 */
class ChapterController extends AuthController
{
    
    /**
     * 浏览
     * @return Response
     */
    public function index(): Response
    {
        return view('novel/chapter/index');
    }

    /**
     * 查询
     * @param Request $request
     * @return Response
     * @throws BusinessException
     */
    public function select(Request $request): Response
    {
        return ChapterLogic::getInstance()->select($request);
    }

    /**
     * 插入
     * @param Request $request
     * @return Response
     * @throws BusinessException
     */
    public function insert(Request $request): Response
    {
        if ($request->method() === 'POST') {
            return ChapterLogic::getInstance()->insert($request);
        }
        return view('novel/chapter/insert',[
            'analyze_content_ai_command'=>config('param.analyze_content_ai_command'),
            'batch_prompt_ai_command'=>getAiCommand('batch_prompt_ai_command'),
            'original_content_ai_command'=>getAiCommand('original_content_ai_command'),
            'content_parts_ai_command'=>getAiCommand('content_parts_ai_command'),
        ]);
    }

    /**
     * 更新
     * @param Request $request
     * @return Response
     * @throws BusinessException
    */
    public function update(Request $request): Response
    {
        if ($request->method() === 'POST') {
            return ChapterLogic::getInstance()->update($request);
        }

        if($request->input('lang') && $request->input('lang')!='cn'){
            return view('novel/chapter/update2',[
                'original_content_ai_command_overseas'=>getAiCommand('original_content_ai_command_overseas'),
            ]);
        }else{
            return view('novel/chapter/update',[
                'analyze_content_ai_command'=>config('param.analyze_content_ai_command'),
                'batch_prompt_ai_command'=>getAiCommand('batch_prompt_ai_command'),
                'original_content_ai_command'=>getAiCommand('original_content_ai_command'),
                'content_parts_ai_command'=>getAiCommand('content_parts_ai_command'),
            ]);
        }

    }

    /**
     * 预览
     * @param Request $request
     * @return Response
     * @throws BusinessException
    */
    public function view(Request $request): Response
    {
        return view('novel/chapter/view');
    }

    /**
     * 删除
     * @param Request $request
     * @return Response
     * @throws \support\exception\BusinessException
     */
    public function delete(Request $request): Response
    {
        return ChapterLogic::getInstance()->delete($request);
    }

    /**
     * 生成生成
     * @param Request $request
     * @return Response
     */
    public function aiRegenerate(Request $request): Response
    {
        return ChapterLogic::getInstance()->aiRegenerate($request);
    }
}
